﻿// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
SerialNumberGenerator generator = new SerialNumberGenerator();
string serialNumber = generator.GenerateSerialNumber();
Console.WriteLine(serialNumber);

public class SerialNumberGenerator
{
    public SerialNumberGenerator()
    {

        // 读取上次记录的日期和自增ID
        string[] lines = File.ReadAllLines("../../counter.txt");
        lastDate = DateTime.Parse(lines[0]);
        dailyCounter = int.Parse(lines[1]);
    }
    private DateTime lastDate = DateTime.Now.Date;
    private int dailyCounter = 0;

    public string GenerateSerialNumber()
    {
        DateTime currentDate = DateTime.Now.Date;

        if (currentDate > lastDate) // 如果当前日期大于上次记录的日期，说明已经过了一天
        {
            lastDate = currentDate; // 更新日期
            dailyCounter = 0; // 重置自增ID
        }

        dailyCounter++; // 每次调用自增ID
        File.WriteAllText("../../counter.txt", $"{lastDate}\n{dailyCounter}");
        string datePart = currentDate.ToString("yyMMdd");
        return "PE" + datePart + "." + dailyCounter.ToString("D4");
    }
}

// 调用示例
